package com.glory.brepda.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.entity.SimpleEntity;

import java.util.List;

/**
 * FileName: MantissaLotListAdapter
 * Author: XJH
 * Date: 2020/7/31 10:19
 * Description:
 * History:
 */
public class MantissaLotListAdapter extends BaseQuickAdapter<SimpleEntity.MantissaLotBinData, BaseViewHolder> {
    boolean isTap = false;
    private int mSelectorPos = -1;
    public MantissaLotListAdapter(@Nullable List<SimpleEntity.MantissaLotBinData> data,boolean isTap) {
        super(R.layout.item_bin_info_list,data);
        this.isTap = isTap;
    }

    @Override
    protected void convert(BaseViewHolder helper, SimpleEntity.MantissaLotBinData item) {
        if (!false){
            helper.setVisible(R.id.cbCheck, true);
        }
        helper.setText(R.id.list_tv1,item.getLOTID());
        helper.setText(R.id.list_tv2,item.getBINNAME());
        helper.setGone(R.id.list_tv3,!isTap);
        helper.setText(R.id.list_tv3,item.getBINDESC());
        helper.setGone(R.id.list_tv4,true);
        helper.setGone(R.id.list_tv5,true);
        helper.setText(R.id.list_tv4,item.getBINGRADE());
        helper.setText(R.id.list_tv5,String.valueOf(item.getMAINQTY()));
        CheckBox checkBox = helper.getView(R.id.cbCheck);

        int position = helper.getAdapterPosition();
        checkBox.setOnClickListener(view -> {
            if (checkBox.isChecked()){
                if (mSelectorPos == -1){
                    mSelectorPos = position;
                }else {
                    getData().get(mSelectorPos).setChecked(false);
                    notifyItemChanged(mSelectorPos);
                    mSelectorPos = position;
                }
            }else {
                mSelectorPos = -1;
            }
        });
    }

    public int getSelectorData(){
        return mSelectorPos ;
    }
}
